from llama_index.llms.openai_like import OpenAILike

# 初始化 OpenAILike 连接本地或兼容 OpenAI API 的服务
llm = OpenAILike(
    model="models/7B/ggml-model-f16.gguf",  # 例如 "qwen-7b-chat", "llama2-chat" 等
    api_base="http://localhost:8080/v1",  # 您的本地 API 服务地址
    api_key="EMPTY",  # 如果无需验证，可设为 "EMPTY" 或 "sk-xxx"
    temperature=0.7,
    max_tokens=512,
    timeout=120
)

# 测试调用
try:
    response = llm.complete("百合花是来源自哪个国家?")
    print(response.text)
except Exception as e:
    print(f"调用失败: {e}")